#!/usr/bin/env python
# coding=UTF-8

from os import walk
from os.path import dirname, abspath, join, splitext
from sys import path, argv
from unittest import TestLoader, TestSuite


###############################################################################


def deriveTestSuites( directory ):
    '''
    Derive all tests recursively starting from the directory.
    '''
    selfDir = dirname( abspath( argv[0] ) )
    testSuites = []
    print( "Searching test modules..." )
    for dirpath, dirnames, filenames in walk( directory ):
        if '.svn' in dirnames:
            dirnames.remove( '.svn' )
        if dirpath.endswith( '/tests' ):
            for filename in filenames:
                moduleName, ext = splitext( filename )
                if ext == '.pyc':
                    continue
                path.append( join( selfDir, dirpath ) )
                print( "  - {0}".format( moduleName ) )
                testSuites.append( TestLoader().loadTestsFromName( moduleName ) )

    return TestSuite( testSuites )


###############################################################################


if __name__ == '__main__':
    print( "This is not an executable script." )

